package com.echo.im.infrastructure.session;

import io.netty.channel.Channel;


/**
 *
 * @author echo
 * @date 2024-08-18
 */
public class SessionContext {

    private static ThreadLocal<UserSession> userSessionThreadLocal=new ThreadLocal<>();

    public static UserSession getSession() {
        // 从请求上下文里获取Request对象
        return userSessionThreadLocal.get();
    }

    public static void setSession(UserSession userSession){
        userSessionThreadLocal.set(userSession);
    }

    public static Channel getChannel(){
        return UserChannelMap.getChannel(getSession().getUserId(), getSession().getTerminal());
    }
}
